#ifndef YCBASEPROTOCOLH
#define YCBASEPROTOCOLH
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>

namespace yc {

struct UploadResourceResponse
{
    explicit UploadResourceResponse(const QByteArray& data)
    {
        QJsonDocument jdoc = QJsonDocument::fromJson(data);
        if (jdoc.isObject()) {
            QJsonObject jo = jdoc.object();
            if (jo.contains("url")) {
                status = 200;
                url = jo["url"].toString();
                tag = jo["tag"].toString();
            } else {
                status = jo["status"].toInt();
                msg = jo["msg"].toString();
                QJsonObject jdata = jo["data"].toObject();
                if (!jdata.isEmpty()) {
                    url = jdata["url"].toString();
                    tag = jdata["tag"].toString();
                }
            }
        }
    }

    int status = 0;
    QString msg;
    QString url;
    QString tag;
};
} // namespace yc

#endif // YCBASEPROTOCOLH
